var imgs = [
    "styles/img/banner.jpg",
    // "styles/img/fang.png",
    // "styles/img/hua.png",
    "styles/img/right_logo.png",
    "styles/img/wuxi.png",
    "styles/img/part1.png",
    "styles/img/part2.png",
    "styles/img/part3.png",
    "styles/img/part2.jpg",
    "styles/img/part3.jpg",
    "styles/img/video.jpg"
];

$(function(){
    loadingFn(imgs,function(){
        setTimeout(function () {
            $('img.fang').fadeIn(1000,function () {
                $('img.hua').fadeIn(800,function () {
                    $('.wuxi').fadeIn(300,function () {
                        $('img.part1').animate({'margin-left':0});
                    });
                })
            })
        },1000)
        if($('.part1_bg').length > 0){
            if($(window).height() > $('.part1_bg').offset().top + 100){
                $('.part1_bg').animate({'opacity':1}).addClass('active');
            }
        }
    });
});

function loadingFn(imgs,callback){
    if(!imgs){return false};
    var img=[];
    var len=imgs.length;
    var loadedCount = 0;
    for(var i=0;i<len;i++){
        img[i]=new Image();
        img[i].src=imgs[i];
        img[i].onload = function(){
            loadedCount++;
            $('.loading-num').html(Math.floor(loadedCount/len*100)+"%").attr('title',Math.floor(loadedCount/len*100));
            if (loadedCount>=len){
                $('.loading-wrap').fadeOut(600,function(){
                    $(this).remove();
                });
                callback ? callback() : null;
            }
        };
    }
}
$('body').scroll(function () {
    var scrollTop = $('body').scrollTop();
    var part1_bg = $('.part1').offset().top - 200;
    var part2 = $('.part2').offset().top - 300;
    var part3 = $('.part3').offset().top;
    if (scrollTop > part1_bg && !$('.part1_bg').hasClass('active')) {
        $('.part1_bg').animate({'opacity':1}).addClass('active');
    }
    if ($('.part2').offset().top < $('body').height()){
        $('.part2').animate({'margin-left':0},500);
        setTimeout(function () {
            $('.part2_bg').animate({'opacity':1},500).addClass('active');
        },1000)
    }
    if($('.part3').offset().top < $('body').height()){
        $('.part3').animate({'margin-left':0},500);
        setTimeout(function () {
            $('.part3_bg').animate({'opacity':1},500).addClass('active');
        },1000)
    }
    if($('.part4').offset().top < $('body').height()){
        $('.part4').animate({'margin-left':0},500);
        setTimeout(function () {
            $('.part4_bg').animate({'opacity':1},500).addClass('active');
        },1000)
    }
})

